package com.eastfair.home.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.HomeServiceInventoryCheckService;
import com.eastfair.venuebooking.api.ServiceInventoryFeign;
import com.eastfair.venueservice.dto.ServiceInventoryCheckDTO;
import com.eastfair.venueservice.dto.ServiceInventoryCheckQuery;
import com.eastfair.venueservice.vo.ServiceInventoryCheckVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author suolong
 * @Date 2022/8/9 9:44
 */

/**
 * <p>
 * 业务实现类
 * 库存盘点
 * </p>
 *
 * @author lye
 * @date 2022-08-09
 */
@Slf4j
@Service
public class HomeServiceInventoryCheckServiceImpl implements HomeServiceInventoryCheckService {

    @Resource
    private ServiceInventoryFeign serviceInventoryFeign;

    @Override
    public Boolean saveInventoryCheck(ServiceInventoryCheckDTO serviceInventoryCheckDTO) {
        R<Boolean> booleanR = serviceInventoryFeign.saveInventoryCheck(serviceInventoryCheckDTO);
        if (!booleanR.getIsSuccess()) {
            throw BizException.wrap(booleanR.getCode(), booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    public Page<ServiceInventoryCheckVO> queryCheckList(PageParams<ServiceInventoryCheckQuery> serviceInventoryCheckQuery) {
        R<Page<ServiceInventoryCheckVO>> pageR = serviceInventoryFeign.queryCheckList(serviceInventoryCheckQuery);
        if (!pageR.getIsSuccess()) {
            throw BizException.wrap(pageR.getCode(), pageR.getMsg());
        }
        return pageR.getData();
    }

    @Override
    public ServiceInventoryCheckVO queryCheckDetailList(ServiceInventoryCheckQuery serviceInventoryCheckQuery) {
        R<ServiceInventoryCheckVO> serviceInventoryCheckVOR = serviceInventoryFeign.queryCheckDetailList(serviceInventoryCheckQuery);
        if (!serviceInventoryCheckVOR.getIsSuccess()) {
            throw BizException.wrap(serviceInventoryCheckVOR.getCode(), serviceInventoryCheckVOR.getMsg());
        }
        return serviceInventoryCheckVOR.getData();
    }

    @Override
    public Boolean updateInventoryCheck(ServiceInventoryCheckDTO serviceInventoryCheckDTO) {
        R<Boolean> booleanR = serviceInventoryFeign.updateInventoryCheck(serviceInventoryCheckDTO);
        if (!booleanR.getIsSuccess()) {
            throw BizException.wrap(booleanR.getCode(), booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    public String queryNewCheckNo() {
        R<String> stringR = serviceInventoryFeign.queryNewCheckNo();
        if (!stringR.getIsSuccess()) {
            throw BizException.wrap(stringR.getCode(), stringR.getMsg());
        }
        return stringR.getData();
    }

    @Override
    public Boolean delInventoryCheck(ServiceInventoryCheckDTO serviceInventoryCheckDTO) {
        R<Boolean> booleanR = serviceInventoryFeign.delInventoryCheck(serviceInventoryCheckDTO);
        if (!booleanR.getIsSuccess()) {
            throw BizException.wrap(booleanR.getCode(), booleanR.getMsg());
        }
        return booleanR.getData();
    }
}
